/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { useEffect, useState, useRef } from 'react';
import { ModalForm, ProFormText } from '@ant-design/pro-form';
import { getShopInfo } from '@/services/Finance/approval';
import type { ProFormInstance } from '@ant-design/pro-form';
import { message, Typography, Image, Button } from 'antd';

const { Paragraph } = Typography;
const Index = (props: { visible: boolean; id: string; onVisibleChange: () => void }) => {
  const formRef = useRef<ProFormInstance>();
  const { visible, id, onVisibleChange, ...rest } = props;
  const [info, setInfo] = useState<{ [name: string]: string }>({});

  useEffect(() => {
    if (visible) {
      getShopInfo({ shop_info_id: id }).then((res) => {
        const { code, data, msg } = res;
        if (code == 0) {
          setInfo(data);
          formRef.current?.setFieldsValue(data);
        } else {
          message.error(msg);
        }
      });
    }
  }, [visible, id]);
  return (
    <ModalForm
      title='新增开票信息'
      formRef={formRef}
      visible={visible}
      width={540}
      layout='horizontal'
      labelCol={{ span: 9 }}
      modalProps={{
        onCancel: onVisibleChange,
      }}
      submitter={{
        render: () => [<Button onClick={onVisibleChange}>关闭</Button>],
      }}
      labelAlign='left'
      {...rest}
    >
      <ProFormText name='invoice_title' label='开票抬头' readonly></ProFormText>
      <ProFormText name='taxpayer_unionid' label='纳税人识别号' readonly></ProFormText>
      <ProFormText name='bank_name' label='开户行' readonly></ProFormText>
      <ProFormText name='bank_account' label='开户账号' readonly></ProFormText>
      <ProFormText name='company_address' label='地址注册地址' readonly></ProFormText>
      <ProFormText name='contact' label='联系方式' readonly></ProFormText>
      <ProFormText
        name='license_name'
        label='营业执照'
        readonly
        addonAfter={<Image width={30} src={info.license_url} />}
      ></ProFormText>
      <ProFormText
        name='qualification_name'
        label='一般纳税人资格认定证明'
        readonly
        addonAfter={<Image width={30} src={info.qualification_url} />}
      ></ProFormText>
      <Paragraph type='danger'>
        注：如需修改开票信息，请联系QQ：2880098661或致电15300770360，给您带来的不便敬请谅解
      </Paragraph>
    </ModalForm>
  );
};

export default Index;
